package com.xhsj.user.hr.process.hrLeaveProcess.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhsj.user.hr.process.dto.hrLeaveProcess.MyLeaveApplyListDto;
import com.xhsj.user.hr.process.dto.hrLeaveProcess.RunLeaveApplyListDto;
import com.xhsj.user.hr.process.hrLeaveProcess.query.*;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import com.xhsj.user.hr.process.hrLeaveProcess.entity.TbHrApprovalLeaveApply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 流程-hr请假申请表 Mapper 接口
 * </p>
 *
 * @author liuqinghua
 * @since 2020-09-01
 */
@Mapper
public interface TbHrApprovalLeaveApplyMapper extends BaseMapper<TbHrApprovalLeaveApply> {

    /**
     * 我的请假申请
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    Page<MyLeaveApplyListQuery> myLeaveApplyList(Page<MyLeaveApplyListQuery> page,
                                                 @Param("userId") Long userId,
                                                 @Param("data") MyLeaveApplyListDto data);

    /**
     * 待审核请假申请列表
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    Page<RunLeaveApplyListQuery> runLeaveApplyList(Page<MyLeaveApplyListQuery> page,
                                                   @Param("roleIdList") List<Long> roleIdList,
                                                   @Param("userId") Long userId,
                                                   @Param("data") RunLeaveApplyListDto data);

    /**
     * 已审核请假申请列表
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    Page<CompletedLeaveApplyList> completedLeaveApplyList(Page<CompletedLeaveApplyList> page,
                                                          @Param("userId") Long userId,
                                                          @Param("data") RunLeaveApplyListDto data);

    // 请假申请基本信息
    LeaveApplyBaseQuery getLeaveApplyBaseList(@Param("dataId") Long dataId);

    /**
     * 全部请假申请列表
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    Page<MyLeaveApplyListQuery> allLeaveApplyList(Page<MyLeaveApplyListQuery> page,
                                                  @Param("data") MyLeaveApplyListDto data);

    // 修改请假申请表last_data
    int updateLeaveApplyById(@Param("id") Long id,@Param("lastData") int lastData);

    /**
     * 请假对应的销假列表
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    List<MyLeaveApplyListQuery> getCancellationLeaveApplyList(@Param("idList") List<Long> idList,
                                                              @Param("data") MyLeaveApplyListDto data);

    /**
     * 按日期查询请假数据
     * @author liuqinghua
     * @param data
     */
    IPage<AllLeaveApplyListByLeaveDateQuery> allLeaveApplyListByLeaveDate(Page<AllLeaveApplyListByLeaveDateQuery> page,
                                                                          @Param("data") MyLeaveApplyListDto data);
    /**
     * 请假对应的销假列表 按日期查询
     * @author liuqinghua
     * @param idList
     */
    List<AllLeaveApplyListByLeaveDateQuery> getCancellationLeaveApplyListByLeaveDate(@Param("idList") List<Long> idList,
                                                                         @Param("data") MyLeaveApplyListDto data);

    /**
     * 我的请假申请删除
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    int deleteMyLeaveApply(@Param("dataId") Long dataId);

    /**
     * 获取已调休总时长
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    int getCompensatoryLeaveTime(@Param("userId") Long userId,
                                 @Param("vacationId") int vacationId);

    /**
     * 获取已销假的总时长
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    int getCancellationLeaveTime(@Param("userId") Long userId,
                                  @Param("vacationId") int vacationId);

    /**
     * 通过用户id列表查询加班调休使用情况
     * @author 苏小林
     * @date 2020/10/26 15:55
     * @param: overTimeExpireDate
     * @param: collect
     * @return: java.util.Map<java.lang.String,java.lang.Object>
     */
    @MapKey("username")
    Map<String, Object> getUseNumberByUserIdsAndExpireDate(@Param("expireDate") Date expireDate, @Param("list") Set<String> list);

    void updateDataBeforeXj(@Param("id") Long id,
                                  @Param("nodeId") Long nodeId);

    /**
     * 查询数据创建人名称
     * @author 苏小林
     * @date 2021/7/22 13:42
     * @param: dataId
     * @return: java.lang.String
     */
    String getFullNameByDataId(@Param("dataId") Long dataId,@Param("tableName") String tableName);

    // 查询用户年度年假使用数量
    int getAnnualLeaveUseNumber(@Param("date") LocalDate date, @Param("userId") Long userId,@Param("dataId") Long dataId);

    /**
     * @Description: 请假统计图数据
     * @Param:date 日期
     * @Author: liuqinghua
     * @Date: 2021/9/6
     */
    List<Map<String, Integer>> getLeaveStatistics(@Param("date") String date,@Param("isNow") boolean isNow);

    List<TbHrApprovalLeaveApply> getList(@Param("userId") long userId, @Param("i") int i);
}
